package com.atguigu.gulimall.common.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

/**
 * author: YangDongDong  <br>
 * date: 2025/3/12 下午10:29  <br>
 *
 * @version 1.0  <br>
 * description:
 */

public class ListValueConstraintValidator implements ConstraintValidator<ListValue, Integer>
{
    private Set<Integer> set = new HashSet<>();

    @Override
    public void initialize(ListValue constraintAnnotation)
    {
        for (int val : constraintAnnotation.vals())
        {
            set.add(val);
        }
    }

    @Override
    public boolean isValid(Integer integer, ConstraintValidatorContext constraintValidatorContext)
    {
        return set.contains(integer);
    }
}
